<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="${path}/pages/">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <title></title>
  <link rel="stylesheet" href="../layui/css/layui.css" media="all">
</head>
<body>
	<div class="layui-fluid">
	<div class="layui-form" style="margin-top: 10px">
		<input type="hidden" id="id" name="id" value="${user.id}">
  		<div class="layui-form-item">
    		<label class="layui-form-label">用户名</label>
    		<div class="layui-input-block">
      			<input type="text" id="uname" name="uname" value="" lay-verify="required|username" placeholder="1" autocomplete="off" class="layui-input">
    		</div>
  		</div>  		
  		<div class="layui-form-item layui-form-text">
    		<label class="layui-form-label">邮箱</label>
    		<div class="layui-input-block">
      			<input type="text" id="email" name="email"  value="" lay-verify="required|email" placeholder="2" autocomplete="off" class="layui-input">
    		</div>
  		</div>  	
  		<div class="layui-form-item layui-hide">
	      	<input type="button" lay-submit lay-filter="lay-form-submit" id="lay-form-submit">
	    </div>
  	</div>
  	</div>
  	<script src="../layui/layui.js"></script>
	<script>
	layui.use(['form','jquery'], function(){
		var form = layui.form;
		var $ = layui.$;
		var id;
		var userName;
		var email;
		
		$.getJSON('${path}/action/user/listInfo', function(data) {
			id=data.id; 
			email=data.email;
			$('#id').attr('value',data.id);
			$('#uname').attr('placeholder',data.userName);
			$('#email').attr('placeholder',data.email);
		});	
		
		 form.verify({
			  username: function(value, item){ //value：表单的值、item：表单的DOM对象
			    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
			      return '用户名不能有特殊字符';
			    }
			    if(/(^\_)|(\__)|(\_+$)/.test(value)){
			      return '用户名首尾不能出现下划线\'_\'';
			    }
			    if(/^\d+\d+\d$/.test(value)){
			      return '用户名不能全为数字';
			    }
			  },
		  		
		  	
		  		email:	function(value, item){ //value：表单的值、item：表单的DOM对象
			   		 if(!new RegExp("^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$").test(value)){
			    	 return '邮箱格式不正确';
			   		 }
				}
			  
			
			});   
		
		
		//监听提交
    	form.on('submit(lay-form-submit)', function(data) {
    		
      		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      		
      		//提交ajax成功后，关闭当前弹层并重载表格
      		$.post('${path}/action/user/update', data.field, function(json) {
      			parent.location.reload();
      			parent.layer.close(index); //再执行关闭    
      			
      			}, 'JSON');
    	});
		
	});	
	
	</script>
  	
  	
</body>
</html>